from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-05 14:26:34.273669
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 05, Aug, 2021
Time: 14:26:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5225
Nobs: 374.000 HQIC: -46.0919
Log likelihood: 4003.14 FPE: 6.60351e-21
AIC: -46.4668 Det(Omega_mle): 5.20761e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.495964 0.096979 5.114 0.000
L1.Burgenland 0.102981 0.050170 2.053 0.040
L1.Kärnten -0.117508 0.024022 -4.892 0.000
L1.Niederösterreich 0.158772 0.106517 1.491 0.136
L1.Oberösterreich 0.083379 0.105193 0.793 0.428
L1.Salzburg 0.293388 0.051223 5.728 0.000
L1.Steiermark 0.011247 0.067827 0.166 0.868
L1.Tirol 0.142648 0.053753 2.654 0.008
L1.Vorarlberg -0.105455 0.048330 -2.182 0.029
L1.Wien -0.059865 0.093916 -0.637 0.524
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.021868 0.234655 -0.093 0.926
L1.Burgenland -0.031828 0.121393 -0.262 0.793
L1.Kärnten 0.035518 0.058125 0.611 0.541
L1.Niederösterreich -0.224752 0.257735 -0.872 0.383
L1.Oberösterreich 0.552057 0.254531 2.169 0.030
L1.Salzburg 0.308082 0.123943 2.486 0.013
L1.Steiermark 0.111032 0.164117 0.677 0.499
L1.Tirol 0.309938 0.130063 2.383 0.017
L1.Vorarlberg -0.018546 0.116942 -0.159 0.874
L1.Wien -0.006441 0.227244 -0.028 0.977
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.263296 0.050311 5.233 0.000
L1.Burgenland 0.096220 0.026027 3.697 0.000
L1.Kärnten -0.005455 0.012462 -0.438 0.662
L1.Niederösterreich 0.225733 0.055260 4.085 0.000
L1.Oberösterreich 0.146840 0.054573 2.691 0.007
L1.Salzburg 0.039406 0.026574 1.483 0.138
L1.Steiermark 0.017860 0.035188 0.508 0.612
L1.Tirol 0.076467 0.027886 2.742 0.006
L1.Vorarlberg 0.056229 0.025073 2.243 0.025
L1.Wien 0.083754 0.048722 1.719 0.086
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199309 0.049173 4.053 0.000
L1.Burgenland 0.044859 0.025439 1.763 0.078
L1.Kärnten -0.005009 0.012180 -0.411 0.681
L1.Niederösterreich 0.126904 0.054010 2.350 0.019
L1.Oberösterreich 0.301319 0.053338 5.649 0.000
L1.Salzburg 0.098922 0.025973 3.809 0.000
L1.Steiermark 0.143139 0.034392 4.162 0.000
L1.Tirol 0.075745 0.027255 2.779 0.005
L1.Vorarlberg 0.055987 0.024506 2.285 0.022
L1.Wien -0.042915 0.047620 -0.901 0.367
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204386 0.098636 2.072 0.038
L1.Burgenland -0.058626 0.051027 -1.149 0.251
L1.Kärnten -0.038006 0.024433 -1.556 0.120
L1.Niederösterreich 0.069706 0.108337 0.643 0.520
L1.Oberösterreich 0.190649 0.106991 1.782 0.075
L1.Salzburg 0.267587 0.052099 5.136 0.000
L1.Steiermark 0.084317 0.068986 1.222 0.222
L1.Tirol 0.127598 0.054671 2.334 0.020
L1.Vorarlberg 0.120735 0.049156 2.456 0.014
L1.Wien 0.035660 0.095521 0.373 0.709
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035186 0.077529 0.454 0.650
L1.Burgenland 0.022010 0.040108 0.549 0.583
L1.Kärnten 0.052539 0.019204 2.736 0.006
L1.Niederösterreich 0.197301 0.085155 2.317 0.021
L1.Oberösterreich 0.344999 0.084096 4.102 0.000
L1.Salzburg 0.048829 0.040950 1.192 0.233
L1.Steiermark -0.003664 0.054224 -0.068 0.946
L1.Tirol 0.114757 0.042972 2.670 0.008
L1.Vorarlberg 0.065409 0.038637 1.693 0.090
L1.Wien 0.124123 0.075081 1.653 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166461 0.093821 1.774 0.076
L1.Burgenland 0.036282 0.048536 0.748 0.455
L1.Kärnten -0.054314 0.023240 -2.337 0.019
L1.Niederösterreich -0.110597 0.103049 -1.073 0.283
L1.Oberösterreich 0.180849 0.101768 1.777 0.076
L1.Salzburg 0.029027 0.049555 0.586 0.558
L1.Steiermark 0.304873 0.065618 4.646 0.000
L1.Tirol 0.487092 0.052002 9.367 0.000
L1.Vorarlberg 0.075068 0.046756 1.606 0.108
L1.Wien -0.111766 0.090858 -1.230 0.219
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154181 0.102691 1.501 0.133
L1.Burgenland -0.007670 0.053125 -0.144 0.885
L1.Kärnten 0.064542 0.025437 2.537 0.011
L1.Niederösterreich 0.204008 0.112791 1.809 0.070
L1.Oberösterreich -0.129417 0.111389 -1.162 0.245
L1.Salzburg 0.248465 0.054240 4.581 0.000
L1.Steiermark 0.158597 0.071822 2.208 0.027
L1.Tirol 0.045223 0.056919 0.795 0.427
L1.Vorarlberg 0.123161 0.051177 2.407 0.016
L1.Wien 0.141990 0.099448 1.428 0.153
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.525031 0.055404 9.476 0.000
L1.Burgenland -0.023326 0.028662 -0.814 0.416
L1.Kärnten -0.009899 0.013724 -0.721 0.471
L1.Niederösterreich 0.188551 0.060854 3.098 0.002
L1.Oberösterreich 0.249255 0.060097 4.148 0.000
L1.Salzburg 0.021134 0.029264 0.722 0.470
L1.Steiermark -0.024070 0.038750 -0.621 0.534
L1.Tirol 0.076008 0.030709 2.475 0.013
L1.Vorarlberg 0.061184 0.027611 2.216 0.027
L1.Wien -0.062108 0.053655 -1.158 0.247
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020781 0.068720 0.131744 0.112774 0.028563 0.061811 -0.001186 0.170348
Kärnten 0.020781 1.000000 -0.059891 0.132382 0.044672 0.052152 0.446085 -0.092656 0.101193
Niederösterreich 0.068720 -0.059891 1.000000 0.286066 0.089394 0.278301 0.015568 0.140919 0.254726
Oberösterreich 0.131744 0.132382 0.286066 1.000000 0.173195 0.296691 0.165496 0.116671 0.127808
Salzburg 0.112774 0.044672 0.089394 0.173195 1.000000 0.124258 0.044522 0.103890 0.048907
Steiermark 0.028563 0.052152 0.278301 0.296691 0.124258 1.000000 0.123617 0.086899 -0.027104
Tirol 0.061811 0.446085 0.015568 0.165496 0.044522 0.123617 1.000000 0.040535 0.126323
Vorarlberg -0.001186 -0.092656 0.140919 0.116671 0.103890 0.086899 0.040535 1.000000 -0.049381
Wien 0.170348 0.101193 0.254726 0.127808 0.048907 -0.027104 0.126323 -0.049381 1.000000